requireJS(['constant', 'site', 'handlebars'], function (Constant, site, Handlebars) {
    var url = {
        list: "manager/orderInfoProduct.do",

        //查询产品是否有关联流程
        queryWorkFlowByProdutId: "manager/queryWorkFlowByProdutId.do"
    }

    site.send({
        url: url.list,
        //async:false
        callback: function (data) {
            data = JSON.parse(data)
            if(data.type === 1){
                var source = $("#product_list_tpl").html();
                var template = Handlebars.compile(source);
                var list = data.content.list;
                var html = template(list);
                $('#product_list').html(html);

                $(".quare").on("click", function () {
                    $(".quare").removeClass('selected');
                    $(".quare").show();
                    $(".quare").find('.selected_img').addClass('hidden')
                    $(this).addClass('selected');
                    $(this).find('.selected_img').removeClass('hidden');
                })

                $(".next").on("click", function () {
                    var product_id = $(".selected").find('.product_name').data('productid');
                    if (!product_id) {
                        Constant.fn.Message('I','请选择产品')
                        return false;
                    }

                    site.send({
                        url: url.queryWorkFlowByProdutId,
                        data: {
                            product_id: product_id
                        },
                        callback: function (data) {
                            data = JSON.parse(data);
                            if (data.type == 1) {
                                if(Constant.getAurlparam('pid')){
                                    pjaxGo("loanBefore/orderIn.html?product_id=" + product_id +"&pid=" +Constant.getAurlparam('pid') +"&type=" + Constant.getAurlparam('type'));
                                }else{
                                    pjaxGo("loanBefore/orderIn.html?product_id=" + product_id);
                                }
                            }
                            else {
                                Constant.fn.Message('F', data.msg);
                            }
                        }
                    })
                })
            }else{
                Constant.fn.Message('F', data.msg);
            }
        }
    })
})